﻿using Models;
using NewTest.Dao;
using NewTest.Demos;
using Oracle.ManagedDataAccess.Client;
using OracleSugar;
using SqlSugarRepository;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            demo();
            Console.WriteLine("执行完毕!");
            Console.ReadKey();
        }
        private static void demo()
        {
            //设置执行的DEMO
            string switchOn = "update";
            //数据库类型
            DbType type = DbType.Oracle;
            //用到oracle才需要设置
            SetSeq();

            switch (switchOn)
            {
                /****************************基本功能**************************************/
                //查询
                case "select": new Select().Init(type); break;
                //插入
                case "insert": new Insert().Init(type); break;
                //更新或插入
                case "insertorupdate": new InsertOrUpdate().Init(type); break;
                //插入
                case "update": new Update().Init(type); break;
                //删除
                case "delete": new Delete().Init(type); break;
                //生成实体
                case "createclass": new CreateClass().Init(type); break;
                //动态多库切换
                case "connection": new Connection().Init(); break;
                //别名表
                case "mappingtable": new MappingTable().Init(type); break;
                //别名列
                case "mappingcolumns": new MappingColumns().Init(type); break;
                //属性方式添加别名
                case "attributesmapping": new AttributesMapping().Init(type); break;
                //事务
                case "tran": new Tran().Init(type); break;
            }
        }
        private static void SetSeq()
        {
            //设置Oracle序列
            OracleSugar.OracleConfig.SequenceMapping = new List<OracleSugar.SequenceModel>() {
                new OracleSugar.SequenceModel() { TableName="student", ColumnName="id", Value="seq" }};
        }
        static void GetList(ISqlSugarClient db,string model_num1, string VerDate, string verId, string parentId, int isFilter)
        {
            List<OracleParameter> paraList = new List<OracleParameter>();
            paraList.Add(new OracleParameter() { ParameterName = "model_num", OracleDbType = OracleDbType.Varchar2 });
            paraList.Add(new OracleParameter() { ParameterName = "ver_date", OracleDbType = OracleDbType.Varchar2 });
            paraList.Add(new OracleParameter() { ParameterName = "verId", OracleDbType = OracleDbType.Varchar2 });
            paraList.Add(new OracleParameter() { ParameterName = "parentIds", OracleDbType = OracleDbType.Varchar2 });
            paraList.Add(new OracleParameter() { ParameterName = "isFilter", OracleDbType = OracleDbType.Int16 });
            paraList.Add(new OracleParameter() { ParameterName = "res", OracleDbType = OracleDbType.Varchar2, Size = 100 });
            paraList.Add(new OracleParameter() { ParameterName = "p_cur", OracleDbType = OracleDbType.RefCursor });

            string df = string.IsNullOrEmpty(verId) ? "" : verId.ToString();
            var pars = paraList.ToArray();
            pars[0].Value = model_num1;
            pars[1].Value = VerDate;
            pars[2].Value = verId;// "550290B2B7C14CE4BF0FEB108859D65A";
            pars[3].Value = parentId;
            pars[4].Value = 1;
            pars[5].Direction = System.Data.ParameterDirection.Output; //将p2设为 output
            pars[6].Direction = System.Data.ParameterDirection.Output; //将p2设为 output
            db.CommandType = System.Data.CommandType.StoredProcedure;
            db.IsClearParameters = false;//禁止清除参数
            var spResult2 = db.SqlQuery<string>("getMbom ", pars.ToList());
            db.CommandType = System.Data.CommandType.Text;
            db.IsClearParameters = true;//可以清除参数
        }
    }
}
